package com.server.tools;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Linux {
	 public static void getDeskUsage() {
	        try {
	            Runtime rt = Runtime.getRuntime();
	            Process p = rt.exec("df -hl /dev/vda1");
	            BufferedReader in = null;
	            try {
	            	
	            	in = new BufferedReader(new InputStreamReader(
	                        p.getInputStream()));
	                String str = in.readLine();
	                str = in.readLine();
	                String[] strArray = str.split(" ");
	                for(String temp : strArray) {
	                	if(temp.endsWith("%")) {
	                		float num = Float.parseFloat(temp.substring(0, temp.length() - 1));
		                	if(num >= 80) {
	                        	MailUtil.sendEmail("397554852@qq.com", "服务端磁盘空间不足", "服务端磁盘使用率已达" + num + "%,请及时清理空间");
	                        	MailUtil.sendEmail("81062048@qq.com", "服务端磁盘空间不足", "服务端磁盘使用率已达" + num + "%,请及时清理空间");
	                        }
	                		break;
	                	}
	                }
	            } catch (Exception e) {
	                e.printStackTrace();
	            } finally {
	                in.close();
	            }
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }
	    public static void main(String[] args) {
	    	getDeskUsage();
	    }
}
